<?php

/**
 * Classe utilizada para armazenar dados do usuario.
 * Use para armazenar dados de navegacao, filtros, etc
 *
 * @author chiquitto
 */
abstract class ZFPainel_Auth_UsuarioDados
{

    /**
     *
     * @var Zend_Auth_Storage_Interface
     */
    private $storage;

    public function setStorage(Zend_Auth_Storage_Interface $storage)
    {
        $this->storage = $storage;
    }

    public function addValues(array $values, $namespace = null, array $options = array())
    {
        if (!$values) {
            return false;
        }

        if (null === $namespace) {
            $namespace = '__';
        }

        $content = (array) $this->storage->read();

        if (!isset($content[$namespace])) {
            $content[$namespace] = array();
        }

        if ((isset($options['setValues'])) and ($options['setValues'])) {
            $content[$namespace] = $values;
        } else {
            $content[$namespace] = $values + $content[$namespace];
        }

        $this->storage->write($content);

        return true;
    }

    public function getValues($namespace = null, $key = null)
    {
        if (null === $namespace) {
            $namespace = '__';
        }

        $content = (array) $this->storage->read();

        if (!isset($content[$namespace])) {
            return null;
        }

        if (null === $key) {
            return $content[$namespace];
        }

        return isset($content[$namespace][$key]) ? $content[$namespace][$key] : null;
    }

}
